<?php
// +----------------------------------------------------------------------
// | WoShiMaiJia Projcet
// +----------------------------------------------------------------------
// | Copyright (c) 2010 http://woshimaijia.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: xinqiyang <517577550@qq.com>
// +----------------------------------------------------------------------
/**
 * 用户模型文件
 * @author xinqiyang
 * @date   2010-4-9
 *
 */
class UserModel extends MetaModel {

	// 自动验证设置 
	protected $_validate     =     array(
	array('email','email','邮箱没填或格式不正确',1,'',1),
	array('email','','邮箱已被使用',1,'unique',1),
	array('password','require','密码必须输入',0,'',1),
	array('enname','charecter','英文名只能由数字,字母,下划线组成',1,'',1),
	array('enname','','名称已被使用',1,'unique',1),
	array ('birthday','date','生日必须输入格式如 1980-01-01',2,'',2),
	array ('qq','qq','QQ号不能为空或者 位数不正确',2,'',2),
	array ('mobile','mobile','手机不能为空,或格式不正确',2,'',2),
	);
	// 自动填充设置 
	protected $_auto     =     array(
	array('image_id','1'),//设置默认头像,使得评论可以成功
	array('password','md5',1,'function'),
	array('createtime','time',1,'function'),
	array('registerip','get_client_ip',1,'function'),
	array ('lastloginip','get_client_ip',2,'function'),
	array ('lastlogintime','time',2,'function'),
	);
	
	/**
	 * 获取单个用户信息
	 * @param $uid
	 */
	function getOneUser($uid)
	{
		if((int)$uid)
		{
			$one = $this->query("select sz_user.id,sz_user.cnname,sz_image.filename,sz_image.url,sz_image.model from sz_user,sz_image where sz_image.id = sz_user.image_id and sz_user.id =".$uid);
			return $one['0'];
		}
	}
	
	/**
	 * 返回用户信息
	 * @param $arr
	 */
	function getUsers($arr)
	{
		//
		return $this->query("select sz_user.id,sz_user.cnname,sz_user.city,sz_user.gogonum,sz_user.shownum,sz_image.filename,sz_image.url,sz_image.model from sz_user,sz_image where sz_image.id = sz_user.image_id and sz_user.id in ".strin($arr));
		
	}
	
	/**
	 * 返回用户信息
	 * @param $arr
	 */
	function newgetUsers($arr)
	{
		//
		return $this->query("select sz_user.id,sz_user.cnname,sz_user.city,sz_user.gogonum,sz_user.shownum,sz_image.filename,sz_image.url,sz_image.model from sz_user,sz_image where sz_image.id = sz_user.image_id and sz_user.id in ".$arr);
		
	}
	
	function getUserTotal()
	{
		$total = $this->query("
		select count(*) from sz_user;
		");
		//dump($total);
		return $total[0]['count(*)'];
	}

}


?>